home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Misc / InstallerNG / developer / savagelib / include / savage / macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-14  |  2.7 KB  |  80 lines

  1.  
  2. #ifndef SAVAGE_MACROS_H
  3. #define SAVAGE_MACROS_H
  4.  
  5. #include <exec/types.h>
  6. #include <exec/nodes.h>
  7. #include <exec/memory.h>
  8. #include <exec/execbase.h>
  9.  
  10. #include <setjmp.h>
  11.  
  12. /******************************************************************************
  13. ** these externs should be defined by the compiler or by the user! the makros
  14. ** below just use them
  15. */
  16.  
  17. /* extern APTR SysBase; */
  18.  
  19. /******************************************************************************
  20. ** this lets you use simple exception handling with standard ansi-c
  21. ** note: never RAISE a value of zero (this would result into an infinite loop)
  22. **
  23. **      TRY
  24. **      {
  25. **           ... RAISE(5); ...
  26. **      }
  27. **      CATCH
  28. **      {
  29. **        switch (exception)
  30. **        {
  31. **          ...
  32. **          case 5:  ...
  33. **          ...
  34. **        }
  35. **      }
  36. **      ENDTRY
  37. */
  38.  
  39. #define TRY       { jmp_buf buf; int exception = setjmp(buf); if (!exception) {
  40. #define CATCH     } else {
  41. #define ENDTRY    } }
  42. #define RAISE(e)  longjmp(buf, e)
  43.  
  44. /******************************************************************************
  45. ** other stuff
  46. */
  47.  
  48. #define MAX(a,b)                       (((a)>(b))?(a):(b))
  49. #define MIN(a,b)                       (((a)<(b))?(a):(b))
  50. #define BPTR2APTR(b)                   (((long)b)<<2)
  51.  
  52. /******************************************************************************
  53. ** these macros replace some savagelib functions :)
  54. */
  55.  
  56. #define sav_PutChar(a,v)               (*((char*)(a)))=((char)(v))
  57. #define sav_PutInt(a,v)                (*((short*)(a)))=((short)(v))
  58. #define sav_PutLong(a,v)               (*((long*)(a)))=((long)(v))
  59. #define sav_GetChar(a)                 (*((char*)(a)))
  60. #define sav_GetInt(a)                  (*((short*)(a)))
  61. #define sav_GetLong(a)                 (*((long*)(a)))
  62. #define sav_Beep()                     DisplayBeep(NULL)
  63. #define sav_Even(n)                    (!((n)&1))
  64. #define sav_BitAND(a,b)                ((a)&(b))
  65. #define sav_BitOR(a,b)                 ((a)|(b))
  66. #define sav_BitXOR(a,b)                ((a)^(b))
  67. #define sav_BitNOT(a)                  (~(a))
  68. #define sav_IsListEmpty(l)             ((((struct List *)(l))->lh_TailPred)==(struct Node *)(l))
  69. #define sav_GetSucc(n)                 (((n)->ln_Succ->ln_Succ)?((n)->ln_Succ):NULL)
  70. #define sav_GetPred(n)                 (((n)->ln_Pred->ln_Pred)?((n)->ln_Pred):NULL)
  71. #define sav_FreeTotalMem()             AvailMem(MEMF_ANY)
  72. #define sav_FreeChipMem()              AvailMem(MEMF_CHIP)
  73. #define sav_FreeFastMem()              AvailMem(MEMF_FAST)
  74. #define sav_FindCOS()                  Output()
  75. #define sav_FindCIS()                  Input()
  76. #define sav_KickVersion()              (((struct ExecBase *)SysBase)->LibNode.lib_Version)
  77.  
  78. #endif
  79.  
  80.